//
// Created on 2025/11/16.
// Author 秦光磊.

#include "render/plugin_render.h"
#include "constant/constant.h"
#include <cstdint>
#include <hilog/log.h>
namespace MyApp {
PluginRender::PluginRender(int64_t &id) {
    OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "PluginRender",
                 "PluginRender START，编号为$d的surfaceID实例化PluginRender成功。");
    id_ = id;
    eglCore_ = new EGLCore();
    hasDraw_ = 0;
    hasChangeColor_ = 0;
}
void PluginRender::ChangeColor() {
    // 改变颜色
    eglCore_->ChangeColor(hasChangeColor_);
}
void PluginRender::DrawPattern() {
    // 绘制
    eglCore_->Draw(hasDraw_);
}
void PluginRender::InitNativeWindow(OHNativeWindow *window) {
    OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "PluginRender", "InitNativeWindow START");
    // 初始化
    eglCore_->EglContextInit(window);
}
void PluginRender::UpdateNativeWindowSize(int width, int height) {
    OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "PluginRender",
                 "UpdateNativeWindowSize START.width:%{public}d,height:%{public}d.", width, height);
    // 更改大小
    eglCore_->UpdateSize(width, height);
    if (!hasChangeColor_ && !hasDraw_) {
        eglCore_->Background();
    }
}
int32_t PluginRender::HadDraw() {
    // 返回已经绘制
    return hasDraw_;
}

int32_t PluginRender::HasChangedColor() {
    // 返回已经更改颜色
    return hasChangeColor_;
}
} // namespace MyApp
